//
//  MBScanNumPopView.m
//  MemberBusiness-ios
//
//  Created by 掌心 on 2018/6/1.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBScanNumPopView.h"

@interface MBScanNumPopView ()
@property (nonatomic,weak) UIView * backShadowView;
@property (nonatomic,weak) UIView * containView;

@end

@implementation MBScanNumPopView

- (instancetype)init
{
    self = [super initWithFrame:[UIScreen mainScreen].bounds];
    if (self) {
        //创建shadowView
        UIView * backShadowView = [[UIView alloc] init];
        backShadowView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.7];
        backShadowView.alpha = 0.0;
        [self addSubview:backShadowView];
        self.backShadowView = backShadowView;
        
        [backShadowView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)]];
        
        [backShadowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self).insets(UIEdgeInsetsZero);
        }];
        
        UIView * containView = [[UIView alloc] initWithFrame:CGRectMake([UIView lf_sizeFromIphone6:32], SCREEN_HEIGHT, SCREEN_WIDTH-[UIView lf_sizeFromIphone6:64], [UIView lf_sizeFromIphone6:200])];
        containView.backgroundColor = [UIColor whiteColor];
        [self addSubview:containView];
        self.containView = containView;
        
        UILabel* titleLabel = [[UILabel alloc]init];
        titleLabel.text = @"验证码核销";
        titleLabel.font = [UIFont lf_mediumFontOfSize:16];
        titleLabel.textColor = [UIColor colorWithR:30 G:30 B:30];
        [containView addSubview:titleLabel];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(containView);
            make.top.equalTo(containView).offset([UIView lf_sizeFromIphone6:34]);
        }];
        
        UIButton* closeButton = [[UIButton alloc]init];
        [closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
        [closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
        [containView addSubview:closeButton];
        
        [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(containView).offset([UIView lf_sizeFromIphone6:-10]);
            make.top.equalTo(containView).offset([UIView lf_sizeFromIphone6:10]);
        }];
        
        UITextField* inpuTextField = [[UITextField alloc]init];
        inpuTextField.placeholder = @"请输入验证码";
        inpuTextField.font = [UIFont lf_systemFontOfSize:12];
        inpuTextField.textColor = [UIColor colorWithR:120 G:120 B:120];
        inpuTextField.layer.borderColor = [UIColor colorWithR:216 G:216 B:216].CGColor;
        inpuTextField.layer.borderWidth = [UIView lf_sizeFromIphone6:1];
        [containView addSubview:inpuTextField];
        
        inpuTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIView lf_sizeFromIphone6:17], 0)];
        inpuTextField.leftViewMode = UITextFieldViewModeAlways;
        [inpuTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset([UIView lf_sizeFromIphone6:20]);
            make.left.equalTo(containView).offset([UIView lf_sizeFromIphone6:46]);
            make.right.equalTo(containView).offset([UIView lf_sizeFromIphone6:-46]);
            make.height.mas_equalTo([UIView lf_sizeFromIphone6:26]);
        }];
        
        UIButton* shureButton = [[UIButton alloc]init];
        //Gradient 0 fill for 矩形 3 拷贝 3
        CAGradientLayer *gradientLayer0 = [[CAGradientLayer alloc] init];
        gradientLayer0.cornerRadius = [UIView lf_sizeFromIphone6:4];
        gradientLayer0.frame = CGRectMake(0, 0, [UIView lf_sizeFromIphone6:196], [UIView lf_sizeFromIphone6:30]);
        gradientLayer0.colors = @[
                                  (id)[UIColor colorWithRed:255.0f/255.0f green:136.0f/255.0f blue:0.0f/255.0f alpha:1.0f].CGColor,
                                  (id)[UIColor colorWithRed:255.0f/255.0f green:99.0f/255.0f blue:0.0f/255.0f alpha:1.0f].CGColor];
        gradientLayer0.locations = @[@0, @1];
        [gradientLayer0 setStartPoint:CGPointMake(0, 0)];
        [gradientLayer0 setEndPoint:CGPointMake(1, 1)];
        [shureButton.layer addSublayer:gradientLayer0];
        [shureButton setTitle:@"核销" forState:UIControlStateNormal];
        shureButton.titleLabel.font = [UIFont lf_systemFontOfSize:14];
        [containView addSubview:shureButton];
        
        [shureButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(inpuTextField.mas_bottom).offset([UIView lf_sizeFromIphone6:40]);
            make.left.equalTo(containView).offset([UIView lf_sizeFromIphone6:54]);
            make.size.mas_equalTo(CGSizeMake([UIView lf_sizeFromIphone6:196], [UIView lf_sizeFromIphone6:30]));
        }];
    }
    return self;
}

- (void)show
{
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.backShadowView.alpha = 1.0;
        self.containView.y = (SCREEN_HEIGHT - self.containView.height)/2;
    }];
}

- (void)close
{
    [self endEditing:YES];
    [UIView animateWithDuration:0.3 animations:^{
        self.backShadowView.alpha = 0.0;
        self.containView.y = SCREEN_HEIGHT;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
